/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.colegiatura.bc;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.cip.esymons.colegiatura.be.Cronograma;

/**
 *
 * @author ADMINISTRADOR
 */
@Stateless
public class CronogramaFacade implements CronogramaFacadeLocal {
    @PersistenceContext
    private EntityManager em;

    public void create(Cronograma cronograma) {
        em.persist(cronograma);
    }

    public void edit(Cronograma cronograma) {
        em.merge(cronograma);
    }

    public void remove(Cronograma cronograma) {
        Cronograma aux = em.merge(cronograma);
        em.remove(aux);
    }

    public Cronograma find(Object id) {
        return em.find(Cronograma.class, id);
    }

    public List<Cronograma> findAll() {
        return em.createQuery("select object(o) from Cronograma as o").getResultList();
    }

    public Cronograma buscaCronograma(String codigo){
        try{
        return (Cronograma) em.createQuery("select object(o) from Cronograma as o where o.croAnio = ?1").setParameter(1, codigo).getSingleResult();
        }catch(Exception ex){
            return null;
        }
    }

    

}
